# -*- coding: utf-8 -*-

"""
	将headers转换为python字典格式
"""
# 引入headers原始数据
def HTTD(headers):

    # 格式化headers
    st1 = headers.split('\n')
    headers_dict = {}
    for text1 in st1:
        try:
            s1 = text1.replace(': ', '#$', 1)
            st2 = s1.split('#$')
            headers_dict[st2[0]] = st2[1]
        except:
            pass

    # 返回字典格式的headers
    return headers_dict

header = '''
Connection: keep-alive
Cookie: install_id=4019449375779358; ttreq=1$4e594dc75197827452871cc4798ece9879de8c47; passport_csrf_token=37b7163131512945c98328dc89518dde; d_ticket=8a2770a7dd286c956e1fdace2eb9b4d4ca4ea; odin_tt=eea31e1660bf63c6461e82261695e924b710d85c8a3b142c9b648193d7a5d8075c4dcf75011903af1faa3ee4e78725d7bdc6a195d4d97b9f5a61c94ff999ab04; sid_guard=145242f4fcabba481f479a33d1e85ca0%7C1588667279%7C5184000%7CSat%2C+04-Jul-2020+08%3A27%3A59+GMT; uid_tt=d6596917291e4380f488b3042c052e86; uid_tt_ss=d6596917291e4380f488b3042c052e86; sid_tt=145242f4fcabba481f479a33d1e85ca0; sessionid=145242f4fcabba481f479a33d1e85ca0; sessionid_ss=145242f4fcabba481f479a33d1e85ca0
X-SS-REQ-TICKET: 1588667688341
X-Tt-Token: 00145242f4fcabba481f479a33d1e85ca0f9843c8f7a6ff6a8674c8fae1afd497d6ace379c0cf3260a2dc749620266e12b1f
sdk-version: 1
X-SS-DP: 1128
x-tt-trace-id: 00-e3f927390d9c7aafc2c2647efc4d0468-e3f927390d9c7aaf-01
User-Agent: com.ss.android.ugc.aweme/100901 (Linux; U; Android 5.1.1; zh_CN; SM-N960F; Build/JLS36C; Cronet/TTNetVersion:8109b77c 2020-04-15 QuicVersion:0144d358 2020-03-24)
Accept-Encoding: gzip, deflate, br
X-Gorgon: 040438a1400170f54d1c9c982cba73781a00368731768f816295
X-Khronos: 1588667688

'''
a = HTTD(header)
print(a)

